
const {ccclass, property} = cc._decorator;

@ccclass
export default class GameDragonEffect{

    /**
     * 动态加载龙骨
     * @param animationDisplay  龙骨组件
     * @param name              龙骨名字
     * @param armatureName      Armature名称
     * @param newAnimation      Animation名称
     * @param completeCallback  动画播放完毕的回调
     * @param playTimes         播放次数 -1是根据龙骨文件 0无限循环 >0是播放次数
     */
    public static loadDragonBones(animationDisplay:dragonBones.ArmatureDisplay,name,armatureName, newAnimation, completeCallback, playTimes = 0)
    {  

        let skepath = "dbMove/" + name + "_ske";
        let texpath = "dbMove/" + name + "_tex";

        cc.loader.loadRes(skepath, (error, dragonBonesJson)=>{
            cc.loader.loadRes(texpath, (error, textureJson) => {

                if(error || textureJson.length <= 0)  return;

                // atlasJson.forEach(asset => {
                //     if(asset instanceof dragonBones.DragonBonesAsset){
                //         animationDisplay.dragonAsset = asset;
                //     }
                //     if(asset instanceof dragonBones.DragonBonesAtlasAsset){
                //         animationDisplay.dragonAtlasAsset  = asset;
                //     }
                // });

                //console.warn(dragonBonesJson,textureJson);

                animationDisplay.dragonAsset = dragonBonesJson;
                animationDisplay.dragonAtlasAsset = textureJson;
              
                animationDisplay.armatureName = armatureName;
                animationDisplay.playAnimation(newAnimation, playTimes);
                animationDisplay.addEventListener(dragonBones.EventObject.COMPLETE, completeCallback);
            })
        })
    }
}
